<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>资管收益列表</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}

        .sq-button.sq-button-round.disabled{
            color: rgba(0,0,0,.30);
            background: #eaeaea;
            border: 1px solid #d8d8d8;
            cursor: not-allowed;
        }
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">承租人名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox" <sys:resourceAuth resCd="noThdOrg">style="display: none" </sys:resourceAuth>>
                    <div class="label">第三方机构</div>
                    <div class="field">
                        <select name="fundRasInsNm" id="fundRasInsNm" value="${fundRasInsNm}">
							<option value="" selected="selected">&nbsp;</option>
							<option value="zyfl">浙银金租</option>
                            <option value="smbc">三井往友</option>
                            <option value="ccfl">长城金租</option>
                            <option value="xbfl">兴邦金租</option>
                            <option value="jxfl">江西金租</option>
                            <option value="shnsbank">上海农商银行</option>
                            <option value="xyfl">兴业金租</option>
                            <option value="xwbank">新网银行</option>
                            <option value="tyfl">天银金融</option>
                            <option value="yxfl">越秀租赁</option>
                            <option value="tianjinbank">天津银行</option>
                            <option value="apfl">安鹏金租</option>
                            <option value="ssfl">上实融资租赁有限公司</option>
                            <option value="zbbankx">武汉众邦银行股份有限公司</option>
						</select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">逾期情况</div>
                    <div class="field">
                        <select name="isOverdue" id="isOverdue" value="${fundRasInsNm}">
							<option value="" selected="selected">&nbsp;</option>
							<option value="0">未逾期</option>
                            <option value="1">已逾期</option>
						</select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">应收时间段</div>
                    <div class="field">
                        <input name="startPayDt" id="startPayDt" type="text" class="ui-datepicker" value="${startPayDt}" ligerui="width: 83">
                        -
                        <input name="endPayDt" id="endPayDt" type="text" class="ui-datepicker" value="${endPayDt}" ligerui="width: 83">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">实收时间段</div>
                    <div class="field">
                        <input name="startLastPayDt" id="startLastPayDt" type="text" class="ui-datepicker" value="${startLastPayDt}" ligerui="width: 83">
                        -
                        <input name="endLastPayDt" id="endLastPayDt" type="text" class="ui-datepicker" value="${endLastPayDt}" ligerui="width: 83">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">资方IRR</div>
                    <div class="field">
                        <input name="startIrrPct" id="startIrrPct" type="text" class="ui-textbox" placeholder="不包含" value="${startIrrPct}" ligerui="width: 83">
                        -
                        <input name="endIrrPct" id="endIrrPct" type="text" class="ui-textbox" placeholder="包含" value="${endIrrPct}" ligerui="width: 83">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                </div>
				<div class="fieldBox col_100" style="display:none;">
			       <div class="field">
			        	<input name="fromPrjFlagNm" id="fromPrjFlagId" type="text" class="ui-textbox" value="${fromPrjFlag}">
			       </div>
			    </div>
            </div>
        </form>
    </div>
 	<div class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>应收/应付合计(元): </b><span id="arAmt"/></td>
                    <td><b>已收/已付合计(元): </b><span id="ovdAmt"/></td>
                    <td><b>应收未收/应付未付合计(元): </b><span id="fineAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>
   </div>

<script type="text/javascript">

$(function() {
	$("#searchBar").ligerForm();
	loadListPage();
	getOvdAmtSummary();
	/* 查询 */
    $("#searchBtn").click(function (event) {
    	var form = new liger.get("searchBar");
    	var data = form.getData();
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
        getOvdAmtSummary();
    });
	/* 清空 */
    $("#clearBtn").click(function(event) {
        var form = liger.get("searchBar");
        form.setData({
            "cstNm": "",
            "lsCntNo": "",
            "startPayDt": "",
            "endPayDt": "",
            "startLastPayDt": "",
            "endLastPayDt": "",
            "startIrrPct": "",
            "endIrrPct": "",
        });
        liger.get("fundRasInsNm").clear();
    });
});

function loadListPage() {
	var form = new liger.get("searchBar");
	var data = form.getData();

	$("#ligergrid1").ligerGrid({
		url: '<%=path%>/institution/earnings/initList.do',
		method : 'get',
		parms:data,
	    columns: [
	        { display:'承租人名称', name:'cstNm', minWidth:140, enabledSort:true}, 
	        { display:'合同号', name:'lsCntNo', minWidth:140, enabledSort:true}, 
	        { display:'资方机构名称', name:'insNm', minWidth:140, enabledSort:true},
	        { display:'应收/应付合计', name:'earAmt', align:'right', minWidth:140, enabledSort:true,
                render:function(rowdata,index,value){
                    if(rowdata.insNm.indexOf('武汉众邦银行') != -1){
                        var earAmt = rowdata.earAmt + rowdata.vouchAmt ;
                        return '&yen;'+FormatMoney(earAmt/100);
                    }else{
                        return '&yen;'+FormatMoney(rowdata.earAmt/100);
                    }
                }
	        },
	        { display:'已收/已付', name:'paidUpAmt', align:'right', minWidth:140, enabledSort:true,
                render:function(rowdata,index,value){
                    if (rowdata.insNm.indexOf('武汉众邦银行') != -1){
                        var paidUpAmt = 0;
                        paidUpAmt = rowdata.paidUpAmt + rowdata.paidVouchAmt ;
                        return '&yen;'+FormatMoney(paidUpAmt/100);
                    }else{
                        return '&yen;'+FormatMoney(rowdata.paidUpAmt/100);
                    }
	            }
	        },
	        { display:'应收未收/应付未付', name:'ovdAmt', align:'right', minWidth:140, enabledSort:true,
                render:function(rowdata,index,value){ return '&yen;'+FormatMoney(rowdata.ovdAmt/100); }
	        },
	        { display:'租金逾期情况', name:'', minWidth:140, enabledSort:true,
	        	render: function (rowdata, rowindex, value, column) { 
					var h = '';
					if(rowdata.isOverdue == 1){//合同到期提醒
						h = '<i class="ico_flasher"></i>';
					}else if(rowdata.validSt == "未续签"){
						h = '<i class="ico_flasher_blue"></i>';
					}
					return h;
				}	
	        }, 
            { display:'资方IRR', name:'zfIrrPct', align:'right', minWidth:120, enabledSort:true,
                render:function(rowdata,index,value){
                    if(rowdata.insNm.indexOf("江西") != -1 ){
                        return "新车8%;二手车10%"
                    }else if(rowdata.insNm.indexOf("新网") != -1 ){
                        return "7.9%"
                    }else if(rowdata.insNm.indexOf("天银") != -1 ){
                        return rowdata.irrPct + "%"
                    }else if(rowdata.insNm.indexOf("天津银行") != -1 ){
                        return "7%"
                    } else if(rowdata.insNm.indexOf("越秀") != -1 ){
                        return "7.5%"
                    } else if(rowdata.insNm.indexOf("上实") != -1 ) {
                        return "8.5%"
                    } else if(rowdata.insNm.indexOf("三井") != -1  ||
                        rowdata.insNm.indexOf("长城") != -1 ){
                        return (rowdata.zfIrrPct == null ? 0 : rowdata.zfIrrPct)+'%';
                    }else{
                        return (rowdata.ourIrrPct == null ? 0 : rowdata.ourIrrPct)+'%';
                    }
                }
            },
            {
                display:'服务费率', name:'svcFeeRate', align:'right', minWidth:120, enabledSort:true,
                render:function (item) {
                    if (item.svcFeeRate) {
                        return item.svcFeeRate * 100 + '%';
                    }else{
                        return '0' ;
                    }
                }
            },
			{
			    display: '操作',
			    isSort: false,
			    width: 100,
			    render: function (rowdata, rowindex, value) {
			    	var h = '';
			    	h += '<a class="sq-button-hasicon" href="javascript:showDetail(';
                    h += "'"+rowdata.lsCntNo+"'";
                    h += ')"><i class="sqBtnIco_4"></i>详情</a>';
			        return h;
			    }
			}
	    ],
	    pageSize:10,
	    root:'rows',
	    record:'total',
	    hideLoadButton : true,
	    width: '100%',
	    height:'100%',
	    heightDiff:-20,
	    //isScroll: false,
	    checkbox:true,
	    delayLoad:true,
	    rownumbers:true,
	});
	grid = liger.get("ligergrid1");
	grid.setHeight(100);
	grid.reload();
}

function showDetail(lsCntNo) {
	var callback = function(){

	};
	var fromPrjFlag = true;
	var _flag = $("#fromPrjFlagId").val(); //来自哪里
	if(StringUtils.isNotEmpty(_flag)) {
		if(_flag == 'false') {
			fromPrjFlag = false;
		}
	}
	//查询参数
	var detailFlag = false;
	var params = "?fromPrjFlag=" + fromPrjFlag + "&lsCntNo=" + lsCntNo;
	Add_navTab('tab_institution_earnings_detail_'+lsCntNo, '资管收益详情', '<%=path%>/institution/earnings/toDetailPage.do'+params, callback);
}


//查询汇总
function getOvdAmtSummary() {
	var form = new liger.get("searchBar");
    var data = form.getData();
    $.ajax({
        type: 'get',
        dataType: 'json',
        data: data,
        url: '<%=path%>/institution/earnings/sumIte.do',
        success: function (msg) {
            $("#arAmt").text(FormatMoney(msg.TOTALEARAMT / 100));
            $("#ovdAmt").text(FormatMoney(msg.TOTALPAIDAMT / 100));
            $("#fineAmt").text(FormatMoney(msg.TOTALOVDAMT / 100));
        }
    });
}
</script>

</body>
</html>
